﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using ConversionInterface;

namespace IPConverter
{
    public partial class SettingsMenu : ParentForm
    {
        public SettingsMenu()
        {
            InitializeComponent();
            this.Load += new EventHandler(SettingsMenu_Load);
        }

        void SettingsMenu_Load(object sender, EventArgs e)
        {
            this.ddlAudio.DataSource = Enum.GetValues(typeof(MediaFile.MediaLanguage));
            this.ddlSub.DataSource = Enum.GetValues(typeof(MediaFile.MediaLanguage));
            this.ddlTargetDevice.DataSource = Enum.GetValues(typeof(ConvertMedia.ConversionTarget));
            this.ddlTargetDevice.SelectedItem = Enum.Parse(typeof(ConvertMedia.ConversionTarget),config.AppSettings.Settings["TargetPlatform"].Value);
            this.ddlAudio.SelectedItem = Enum.Parse(typeof(MediaFile.MediaLanguage),config.AppSettings.Settings["AudioLanguage"].Value);
            this.ddlSub.SelectedItem = Enum.Parse(typeof(MediaFile.MediaLanguage),config.AppSettings.Settings["SubtitleLanguage"].Value);
            this.txtOutputDir.Text = config.AppSettings.Settings["OutputDirectory"].Value;
            this.chkShowNetworkDrives.Checked = config.AppSettings.Settings["ShowNetworkDrives"].Value == "true";
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            config.AppSettings.Settings["TargetPlatform"].Value = this.ddlTargetDevice.SelectedItem.ToString();
            config.AppSettings.Settings["SubtitleLanguage"].Value = this.ddlSub.SelectedItem.ToString();
            config.AppSettings.Settings["AudioLanguage"].Value = this.ddlAudio.SelectedItem.ToString();
            config.AppSettings.Settings["OutputDirectory"].Value = this.txtOutputDir.Text;
            config.AppSettings.Settings["ShowNetworkDrives"].Value = this.chkShowNetworkDrives.Checked ? "true" : "false";
            config.Save(ConfigurationSaveMode.Modified);
            this.Close();
        }

        private void btnBrowse_Click(object sender, EventArgs e)
        {
            if (this.folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                this.txtOutputDir.Text = folderBrowserDialog1.SelectedPath;
            }
        }
    }
}
